from typing import List


class TreeNode:
    def __init__(self, val: int):
        self.left = None
        self.right = None
        self.val = val


def side_view(root: TreeNode) -> List[int]:
    queue = [root, None]
    level = []
    result = []
    while queue:
        node = queue.pop(0)
        if node is not None:
            level.append(node.val)
            if node.left:
                queue.append(node.left)
            if node.right:
                queue.append(node.right)
        else:
            if level:
                result.append(level[-1])
                level = []
                queue.append(None)
    return result


def buildTree(input: List[int]) -> TreeNode:
    nodes = [TreeNode(x) for x in input]
    for i in range(1, len(input)):
        if input[i] is None:
            continue
        parent = (i + 1) // 2 - 1
        if i % 2 == 1:
            nodes[parent].left = nodes[i]
        else:
            nodes[parent].right = nodes[i]
    return nodes[0]


print(side_view(buildTree([1, 2, 3, None, 5, None, 4])))
